from api.base_api import BaseApi
from common.read_json import read_json
import unittest
from parameterized import parameterized
from common.assert_common import assert_common
from common.html_util import html_util

class TestOpenAccount(unittest.TestCase):
    def setUp(self) -> None:
        self.openaccount_api = BaseApi()
    def tearDown(self) -> None:
        self.openaccount_api.session.close()

    @parameterized.expand(read_json('open_account','realname'))
    def test01_realname(self,keywords,password,realname,card_id,exp_status_code,exp_status,description,check):
        self.openaccount_api.reg_login_mode().user_login(keywords,password)
        response = self.openaccount_api.open_account_mode().realname(realname,card_id)
        json_data = response.json()
        assert_common(self,response,exp_status_code,exp_status,description)
        if check == 0:
            self.assertEqual('450****798',json_data['data']['card_id'])
            self.assertEqual('楚**',json_data['data']['realname'])

    def test02_open_account(self):
        self.openaccount_api.reg_login_mode().user_login("15878945622", "l123456")
        response = self.openaccount_api.open_account_mode().open_account()
        assert_common(self,response,200,200,'form')

    def test03_third_open_account(self):
        self.openaccount_api.reg_login_mode().user_login("15878945622", "l123456")
        response_op = self.openaccount_api.open_account_mode().open_account()
        url = html_util(response_op)[0]
        form_data = html_util(response_op)[1]
        response_three = self.openaccount_api.open_account_mode().third_open_account(url,form_data)
        self.assertEqual(200,response_three.status_code)
        self.assertIn('OK',response_three.text)

